# encoding: utf-8
"""
@author: 夏洛
@QQ: 1972386194
@file: 01-demo.py
"""

import requests
import execjs
headers = {
    "Accept": "text/html, */*; q=0.01",
    "Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6",
    "Cache-Control": "no-cache",
    "Pragma": "no-cache",
    "Referer": "http://q.10jqka.com.cn/",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36",
    "X-Requested-With": "XMLHttpRequest",
}

def get_cookie_v():
    res = requests.get('http://127.0.0.1:5000')
    data = res.json()
    v = data.get('context').get('v')
    return v

def jsdom_cookie_v():
    v = execjs.compile(open('04-同花顺.js','r',encoding='utf-8').read()).call('get_cookie')
    print(v)
    return v


def ex_dom_v():
    # 云主机   公网IP
    params = {
        'data': 'xialuo',
    }
    res = requests.get('http://127.0.0.1:8000',params=params)
    import json
    items = json.loads(res.text)
    v = items.get('v')
    return v


def get_data():
    v = get_cookie_v()
    headers['Cookie'] = 'v=' + v
    headers['hexin-v'] =  v
    print(headers)
    url = "http://q.10jqka.com.cn/index/index/board/all/field/zdf/order/desc/page/2/ajax/1/"
    response = requests.get(url,  headers=headers,verify=False)
    print(response.text)

get_data()


def get_test():
    headers = {'Accept': 'text/html, */*; q=0.01', 'Accept-Language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,zh-TW;q=0.6', 'Cache-Control': 'no-cache', 'Connection': 'keep-alive', 'Pragma': 'no-cache', 'Referer': 'http://q.10jqka.com.cn/', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36', 'X-Requested-With': 'XMLHttpRequest', 'Cookie': 'v=A8TkiDQYegL9sc5OQvDQ5EhDlUm23ehHqgF8i95lUA9SCWpjBu241_oRTBgt', 'hexin-v': 'A8TkiDQYegL9sc5OQvDQ5EhDlUm23ehHqgF8i95lUA9SCWpjBu241_oRTBgt'}
    url = "http://q.10jqka.com.cn/index/index/board/all/field/zdf/order/desc/page/2/ajax/1/"
    response = requests.get(url, headers=headers, verify=False)
    print(response.text)
# get_test()
